package com.zcily.demo.controller;


import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.util.SaResult;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.zcily.demo.model.entity.User;
import com.zcily.demo.model.form.UserForm;
import com.zcily.demo.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * <p>
 * 用户表 前端控制器
 * </p>
 *
 * @author CGG
 * @since 2025-11-05
 */
@RestController
@RequestMapping("/user")
@Api(tags = "用户信息")
public class UserController {

    @Resource
    private UserService userService;

    // 用户列表  ---- http://localhost:6710/user/paging?current=2&size=10
    @GetMapping("/paging")
    @ApiOperation(value = "用户列表", notes = "权限码 = system:user:list")
    @SaCheckPermission("system:user:list")
    public SaResult paging(UserForm form) {
        LambdaQueryWrapper<User> wrapper = new LambdaQueryWrapper<>();
        wrapper.ne(User::getUsername, "admin");
        IPage<User> data = userService.page(form, wrapper);
        return SaResult.data(data);
    }

    // 用户详情  ---- http://localhost:6710/user/detail/1613819003225870337
    @GetMapping("/detail/{id}")
    @ApiOperation(value = "用户详情", notes = "权限码 = system:user:queryById")
//    @SaCheckPermission("system:user:queryById")
    public SaResult detail(@PathVariable("id") String userId) {
        LambdaQueryWrapper<User> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(User::getId, userId);
        User user = userService.getOne(wrapper);
        return SaResult.data(user);
    }
}
